package wxapp

import (
	"context"
	"errors"
	"hotgo/internal/service"

	v1 "hotgo/api/api/wxapp/v1"
)

func (c *ControllerV1) Phone(ctx context.Context, req *v1.PhoneReq) (res *v1.PhoneRes, err error) {
	res = &v1.PhoneRes{}
	openid := ctx.Value("openid").(string)
	phoneRes, errs := c.wxappHandler.PhoneNumber.GetUserPhoneNumber(ctx, req.Code)
	if nil != errs {
		return res, errs
	}
	if 0 != phoneRes.ErrCode {
		return res, errors.New(phoneRes.ErrMsg)
	}
	//ctx.Value()
	err = service.Wxapp().SetUserPhone(ctx, openid, phoneRes.PhoneInfo.PurePhoneNumber)
	return

}
